package core

import (
	"flag"
	"os"
)

type ParamInfo struct {
	help       bool
	version    bool
	Completion bool   // 获取补全单词
	Words      string // 需要翻译的词句
}

func (p *ParamInfo) Parse() {
	flag.BoolVar(&p.help, "h", false, "Show this help.")
	flag.BoolVar(&p.version, "v", false, "Show version.")
	flag.BoolVar(&p.Completion, "c", false, "Show completions")
	flag.Parse()

	if p.help {
		flag.Usage()
		os.Exit(0)
	}
	if p.version {
		println("baidufy v0.0.1")
		os.Exit(0)
	}
	// 拼接所有未识别的参数, 作为输入内容
	for _, v := range flag.Args() {
		if len(p.Words) > 0 {
			p.Words += " "
		}
		p.Words += v
	}
}
